#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

void solve() {
	string s;
	cin >> s;
	int n = s.length();
	int l = 0, r = n - 1;
	while (l <= r) {
		if (s[l] != s[r]) {
			cout << 2 << endl; 
			return;
		}
		l++;
		r--;
	}
	cout << 1 << endl;
}

int main() {
	int t;
	cin >> t;
	while (t-- > 0) {
		solve();
	}
	return 0;
}
